package com.hzhr.iot.device.dao;

import com.hzhr.iot.device.dao.mapper.custom.DeviceInfoCardEntityCustomMapper;
import com.hzhr.iot.device.dao.mapper.generator.DeviceInfoCardEntityMapper;
import com.hzhr.iot.device.entity.DeviceInfoCardEntity;
import com.hzhr.iot.device.entity.ext.DeviceInfoCardEntityExt;
import com.hzhr.iot.device.queryModel.custom.DeviceInfoCardCustomQueryModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class DeviceInfoCardDao {
    @Autowired
    DeviceInfoCardEntityMapper deviceInfoCardEntityMapper;
    @Autowired
    DeviceInfoCardEntityCustomMapper deviceInfoCardEntityCustomMapper;

    public int insert(DeviceInfoCardEntity record) {
        if (record == null) return 0;
        int changeCount = deviceInfoCardEntityMapper.insert(record);
        return changeCount;
    }

    public int delete(DeviceInfoCardCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int changeCount = deviceInfoCardEntityCustomMapper.delete(queryModel);
        return changeCount;
    }

    public int update(DeviceInfoCardEntity record) {
        if (record == null) return 0;
        int changeCount = deviceInfoCardEntityMapper.updateByPrimaryKey(record);
        return changeCount;
    }

    public int updateProps(DeviceInfoCardCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int changeCount = deviceInfoCardEntityCustomMapper.updateProps(queryModel);
        return changeCount;
    }

    public DeviceInfoCardEntity selectEntity(DeviceInfoCardCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<DeviceInfoCardEntityExt> extList = deviceInfoCardEntityCustomMapper.selectExt(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }
    public List<DeviceInfoCardEntity> selectEntityList(DeviceInfoCardCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<DeviceInfoCardEntityExt> extList = deviceInfoCardEntityCustomMapper.selectExt(queryModel);
        if (extList == null) return null;
        List<DeviceInfoCardEntity> entityList = new ArrayList<>();
        for (DeviceInfoCardEntityExt ext : extList) {
            entityList.add(ext);
        }
        return entityList;
    }

    public DeviceInfoCardEntityExt selectExt(DeviceInfoCardCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<DeviceInfoCardEntityExt> extList = deviceInfoCardEntityCustomMapper.selectExt(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }
    public List<DeviceInfoCardEntityExt> selectExtList(DeviceInfoCardCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<DeviceInfoCardEntityExt> extList = deviceInfoCardEntityCustomMapper.selectExt(queryModel);
        return extList;
    }


    // 自定义or查询
    public List<DeviceInfoCardEntityExt> selectExtList1(DeviceInfoCardCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<DeviceInfoCardEntityExt> extList = deviceInfoCardEntityCustomMapper.selectExt1(queryModel);
        return extList;
    }


    public DeviceInfoCardEntityExt selectEntity1(DeviceInfoCardCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<DeviceInfoCardEntityExt> extList = deviceInfoCardEntityCustomMapper.selectExt1(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }

    public int selectCount(DeviceInfoCardCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int count = deviceInfoCardEntityCustomMapper.selectCount(queryModel);
        return count;
    }
}
